package com.dyz.leetcode._01_array;

import java.util.ArrayList;
import java.util.List;

public class _228_summaryRanges {
    public List<String> summaryRanges(int[] nums) {
        List<String> res = new ArrayList<>();
        int n = nums.length;
        int i=0;
        while(i<n){
            int low = i;
            i++;
            while(i<n && nums[i]-nums[i-1]==1){i++;}
            int hign = i-1;
            StringBuilder sb = new StringBuilder(String.valueOf(nums[low]));
            //可能最后只有一个如 ["0->2","4->5","7"]
            if(low<hign){
                sb.append("->"+nums[hign]);
            }

            res.add(sb.toString());
        }
        return res;
    }

    public static void main(String[] args) {
        int [] nums = {0,1,2,4,5,7};
        new _228_summaryRanges().summaryRanges(nums);
    }
}
